package com.example.back.dao;

import com.example.back.bean.SystemFunction;
import com.example.back.bean.SystemRole;
import com.example.back.bean.SystemUser;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface SystemDao {
    @Select("select * from w_system_user where name=#{userName}")
    public SystemUser getUserInfo(String userName);

    @Update("update w_system_user set loginTime=now(),failureNum=#{failureNum} where id=#{id}")
    void updateFailureNum(Integer id,Integer failureNum);

    @Update("update w_system_user set loginTime=now(),status=1 where id=#{id}")
    void updateLoginStatus(Integer id);

    @Update("update w_system_user set loginTime=now(),failureNum=0 where id=#{id}")
    void updateLoginFailureNum(Integer id);

    @Update("update w_system_user set passWord = #{passWord},failureNum=0 where name=#{name}")
    boolean updatePassWord(String name,String password);

    @Select("select w_system_role.id,w_system_role.name,w_system_role.organizationId,w_system_role.description from w_system_role ,w_system_user_role_relation where w_system_user_role_relation.roleId=w_system_role.id and userId=#{userId}")
    List<SystemRole> getSystemRoleInfo(Integer userId);

    @Select("select w_system_function.id,w_system_function.route,w_system_function.parameter,w_system_function.superior,w_system_function.name,w_system_function.type from w_system_role_function_relation,w_system_function where w_system_role_function_relation.functionId=w_system_function.id and w_system_role_function_relation.roleId=#{systemRoleId}")
    List<SystemFunction> getSystemFunction(Integer systemRoleId);
}
